﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Utility;
using LotteryVote.Logic.Web;

namespace LotteryVote.Controls
{
    public partial class DropWaterSearch : BaseControl
    {
        private bool _displayCompany = true;

        public bool IsSearch
        {
            get
            {
                var searchStr = Request.QueryString["Search"];
                return !string.IsNullOrEmpty(searchStr) && searchStr == "true";
            }
        }
        public event EventHandler OnSearch;
        public string Num
        {
            get
            {
                return txt_num.Text;
            }
        }
        public int CompanyId
        {
            get
            {
                return lv_company.SelectedValue;
            }
        }
        public int GamePlayWayId
        {
            get
            {
                return lv_gameplayway.GamePlayWayId;
            }
        }
        public double DropValue
        {
            get
            {
                if (!string.IsNullOrEmpty(txt_dropwater.Text) && txt_dropwater.Text.IsFloat())
                    return double.Parse(txt_dropwater.Text);
                return 0;
            }
        }
        public decimal Amount
        {
            get
            {
                if (!string.IsNullOrEmpty(txt_amount.Text) && txt_amount.Text.IsFloat())
                    return decimal.Parse(txt_amount.Text);
                return 0;
            }
        }
        public bool DisplayCompany
        {
            get
            {
                return _displayCompany;
            }
            set
            {
                _displayCompany = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Execute(() =>
            //{
            //    InitParams();
            //});
        }
        protected override void OnInit(EventArgs e)
        {
            InitParams();
            base.OnInit(e);
        }
        void InitParams()
        {
            if (IsSearch)
            {
                string num = Request.QueryString["num"];
                if (!string.IsNullOrEmpty(num))
                    txt_num.Text = num;
                string company = Request.QueryString["company"];
                if (!string.IsNullOrEmpty(company) && company.IsNum())
                {
                    var companyId = int.Parse(company);
                    lv_company.SelectedValue = companyId;
                }
                string gameplayway = Request.QueryString["gameplayway"];
                if (!string.IsNullOrEmpty(gameplayway) && gameplayway.IsNum())
                {
                    var gameplaywayId = int.Parse(gameplayway);
                    lv_gameplayway.GamePlayWayId = gameplaywayId;
                }
                string dropwater = Request.QueryString["dropwater"];
                if (!string.IsNullOrEmpty(dropwater) && dropwater.IsFloat())
                {
                    txt_dropwater.Text = dropwater;
                }
                string amount = Request.QueryString["amount"];
                if (!string.IsNullOrEmpty(amount) && amount.IsFloat())
                {
                    txt_amount.Text = amount;
                }
                if (OnSearch != null)
                    OnSearch(this, EventArgs.Empty);
            }
        }

    }
}